<div class="content-wrapper">

    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right">
            <?php if ($this->cancelOrderCount > 0) { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'deleteCancelOrder']); ?>" class="btn btn-sm btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('一键删除已取消订单'); ?></a>
            <?php } ?>
            <?php echo $this->HelpUrl('orderList'); ?>
        </h1>

    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>
        <div class="row">
            <div class="col-xs-12">
                <div class="box shop-box">

                    <div class="box-body table-responsive no-padding">
                        <table class="table shop-table table-hover">
                            <thead>
                            <tr class="shop-bg-thead">
                                <!--th width="2%"><input type="checkbox" class="minimal select-all-checkbox"></th-->
                                <th style="width: 25%"><?php echo $this->translate('订单编号'); ?></th>
                                <th style="width: 12%"><?php echo $this->translate('买家'); ?></th>
                                <th style="width: 10%"><?php echo $this->translate('状态'); ?></th>
                                <th style="width: 8%"><?php echo $this->translate('金额'); ?></th>
                                <th style="width: 10%"><?php echo $this->translate('配送类型'); ?></th>
                                <th style="width: 16%">
                                    <?php echo $this->translate('时间'); ?>
                                </th>
                                <th style="width: 18%"><?php echo $this->translate('操作'); ?></th>
                            </tr>
                            <?php
                            $sForm = $this->searchForm;
                            $sForm->prepare();
                            $sForm->get('order_status')->setEmptyOption('状态');
                            $sForm->get('delivery_type')->setEmptyOption('选择');
                            ?>
                            <?php echo $this->form()->openTag($sForm); ?>
                            <tr>
                                <!--td></td-->
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_sn')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_sn'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('user_name')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('user_name'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_status')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_status'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('order_amount')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('order_amount'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <?php echo $this->formElement($sForm->get('delivery_type')); ?>
                                    <?php echo $this->formElementErrors($sForm->get('delivery_type'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <div class="input-group" style="margin-bottom: 5px;">
                                        <span class="input-group-addon" style="padding: 0;">
                                            <?php echo $this->formElement($sForm->get('time_type')); ?>
                                        </span>
                                        <?php echo $this->formElement($sForm->get('start_time')); ?>
                                    </div>
                                    <div class="input-group">
                                        <span class="input-group-addon" style="font-size: 13px;"><?php echo $this->translate('同上'); ?></span>
                                        <?php echo $this->formElement($sForm->get('end_time')); ?>
                                    </div>
                                    <?php echo $this->formElementErrors($sForm->get('start_time'), ['class'=>'error-message']);?>
                                    <?php echo $this->formElementErrors($sForm->get('end_time'), ['class'=>'error-message']);?>
                                </td>
                                <td>
                                    <button type="submit" class="btn btn-info btn-sm"><i class="fa fa-search"></i></button>
                                    <?php
                                    $formData = array_filter($sForm->getData());
                                    if(!empty($formData) || (isset($formData['order_status']) && $formData['order_status'] != '')) { ?>
                                        &nbsp;&nbsp;<a href="<?php echo $this->url('sales');?>" class="btn btn-default btn-sm"><i class="fa fa-reply"></i></a>
                                    <?php } $formData['page'] = $this->orderList->getCurrentPageNumber(); ?>
                                </td>
                            </tr>
                            <?php echo $this->form()->closeTag(); ?>
                            </thead>
                            <tbody>
                            <?php if($this->orderList->getCurrentItemCount() > 0) foreach ($this->orderList as $orderValue) { ?>
                                <tr>
                                    <!--td><input name="select_id[]" value="<?php echo $orderValue->getOrderId(); ?>" type="checkbox" ></td-->
                                    <td>
                                        <?php echo $orderValue->getOrderSn(); ?>
                                        <p style="margin-bottom: 2px;">
                                            <?php foreach($orderValue->getOrderGoods() as $goodsValue) { ?>
                                            <a href="<?php echo $this->url('shop-goods', ['id' => $goodsValue->getGoodsId()]); ?>" target="_blank">
                                                <img src="<?php echo $this->goodsHelper()->goodsImage($goodsValue->getGoodsImage()); ?>" title="<?php echo $this->escapeHtml($goodsValue->getGoodsName().(!empty($goodsValue->getInSpecGoodsStr()) ? '  '.$goodsValue->getInSpecGoodsStr() : '')); ?>" alt="<?php echo $this->escapeHtml($goodsValue->getGoodsName().'&nbsp;&nbsp;'.$goodsValue->getInSpecGoodsStr()); ?>" class="img-thumbnail" style="width: 40px;height: 40px;">
                                            </a>
                                            <?php } ?>
                                        </p>
                                        <?php if (!empty($orderValue->getOrderNotes())) { ?>
                                            <small class="text-blue"><?php echo $this->escapeHtml($orderValue->getOrderNotes()); ?></small>
                                        <?php } ?>
                                    </td>
                                    <td><?php echo $this->escapeHtml($orderValue->getUserName()); ?></td>
                                    <td><?php echo $this->salesHelper()->getOrderStatus($orderValue->getOrderStatus()); ?></td>
                                    <td><?php echo $this->shopCurrencyFormat($orderValue->getOrderAmount(), null, $orderValue->getCurrencyCode()); ?></td>
                                    <td><?php echo $this->salesHelper()->getDeliveryTypeName($orderValue->getDeliveryType()); ?></td>
                                    <td>
                                        <span class="badge bg-blue" title="<?php echo $this->translate('下单'); ?>"><i class="fa fa-shopping-bag" aria-hidden="true"></i></span> <small><?php echo $this->shopDateFormat()->orderTime($orderValue->getOrderAddTime()); ?></small>
                                        <?php if ($orderValue->getPaymentFinishTime()) { ?>
                                            <br><span class="badge bg-blue" title="<?php echo $this->translate('付款'); ?>"><i class="fa fa-credit-card" aria-hidden="true"></i></span> <small><?php echo $this->shopDateFormat()->orderTime($orderValue->getPaymentFinishTime()); ?></small>
                                        <?php } ?>
                                        <?php if ($orderValue->getExpressTime()) { ?>
                                            <br><span class="badge bg-blue" title="<?php echo $this->translate('发货'); ?>"><i class="fa fa-truck" aria-hidden="true"></i></span> <small><?php echo $this->shopDateFormat()->orderTime($orderValue->getExpressTime()); ?></small>
                                        <?php } ?>
                                        <?php if ($orderValue->getOrderFinishTime()) { ?>
                                            <br><span class="badge bg-blue" title="<?php echo $this->translate('收货'); ?>"><i class="fa fa-home" aria-hidden="true"></i></span> <small><?php echo $this->shopDateFormat()->orderTime($orderValue->getOrderFinishTime()); ?></small>
                                        <?php } ?>
                                    </td>
                                    <td>
                                        <a href="<?php echo $this->url('sales',
                                            ['action'=>'detail', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"
                                           class="btn btn-xs btn-success"><i class="fa fa-info-circle"></i> <?php echo $this->translate('详情'); ?></a>

                                        <?php if($orderValue->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('WAIT_PAYMENT') && $orderValue->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')) { ?>
                                        <div class="btn-group">
                                            <button type="button" class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><?php echo $this->translate('更多'); ?> <span class="caret"></span></button>
                                            <ul class="dropdown-menu">
                                                <?php if($this->salesHelper()->cancelOrder($orderValue)) { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'cancelOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('取消订单'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if($this->salesHelper()->payOrder($orderValue)) { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'payOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单付款'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if($this->salesHelper()->shipOrder($orderValue)) { ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action' => ($orderValue->getDeliveryType() == 'autoDelivery' ? 'sendOrderGoodsVirtual' : 'shipOrder'), 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单发货'); ?></small></a></li>
                                                <?php } ?>
                                                <?php if($this->salesHelper()->receiptOrder($orderValue)) { ?>
                                                    <?php
                                                    if ($this->salesHelper()->orderExpressTrack($orderValue, $this->deliveryIdArray)) { ?>
                                                        <li><a href="<?php echo $this->url('sales', ['action'=>'showOrderExpressTrack', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>" target="_blank"><small><?php echo $this->translate('物流轨迹'); ?></small></a></li>
                                                    <?php } ?>
                                                    <li><a href="<?php echo $this->url('sales', ['action'=>'receiptOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>"><small><?php echo $this->translate('订单收货'); ?></small></a></li>
                                                <?php } ?>
                                            </ul>
                                        </div>
                                        <?php } ?>

                                        <a href="<?php echo $this->url('sales', ['action'=>'printOrder', 'id'=>$orderValue->getOrderId()], ['query' => $formData]); ?>" class="btn btn-xs btn-primary"><i class="fa fa-print"></i> <?php echo $this->translate('打印'); ?></a>

                                        <?php if($orderValue->getOrderStatus() == $this->salesHelper()->getOrderStatusCode('CANCEL_ORDER')) { ?>
                                            <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该订单吗?'); ?>', '<?php echo $this->url('sales', ['action'=>'delete', 'id'=>$orderValue->getOrderId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> <?php echo $this->translate('删除'); ?></a>
                                        <?php } ?>
                                    </td>
                                </tr>
                            <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <!--div class="pull-left">
                            <input type="checkbox" class="minimal select-all-checkbox"> <?php echo $this->translate('全选'); ?>
                            <select name="editAllState">
                                <option value=""><?php echo $this->translate('选择状态'); ?></option>
                                <option value="cancelOrder"><?php echo $this->translate('取消'); ?></option>
                                <option value="deleteOrder"><?php echo $this->translate('删除'); ?></option>
                            </select>
                            <button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('更新'); ?></button>
                        </div-->
                        <?php echo $this->paginationControl($this->orderList, 'Sliding', 'layout/page', ['route' => 'sales']); ?>
                    </div>
                </div>

            </div>
        </div>

    </section>
</div>
<script type="text/javascript">
    laydate.render({elem: '#start_time'});
    laydate.render({elem: '#end_time'});
</script>